define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'steward_withdraw/index' + location.search,
                    add_url: 'steward_withdraw/add',
                    edit_url: 'steward_withdraw/edit',
                    del_url: 'steward_withdraw/del',
                    multi_url: 'steward_withdraw/multi',
                    import_url: 'steward_withdraw/import',
                    table: 'steward_withdrawal',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible: true,// 默认显示搜索条件
                search: false,// 搜索框
                commonSearch: false,// 搜索按钮
                showToggle: false,// 切换视图
                showColumns: false,// 显示列
                showExport: false,// 导出按钮
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'steward.realname', title: __('申请管家'), operate: 'LIKE'},
                        // {field: 'bank_id', title: __('Bank_id')},
                        {field: 'cardholder', title: __('Cardholder'), operate: 'LIKE'},
                        {field: 'bank', title: __('Bank'), operate: 'LIKE'},
                        {field: 'branch', title: __('Branch'), operate: 'LIKE'},
                        {field: 'cardnumber', title: __('Cardnumber'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"1":__('待审核'),"2":__('已通过'),"3":__('已拒绝')}, formatter: Table.api.formatter.status},

                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('按钮组'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'examine',
                                    text: __('审核'),
                                    title: __('审核'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-pencil-square-o',
                                    url: 'steward_withdraw/example',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.status == '1'){
                                            return true;
                                        }
                                        return false;
                                    }
                                },
                                {
                                    name: 'delete',
                                    text: __('删除'),
                                    title: __('删除'),
                                    classname: 'btn btn-xs btn-danger btn-delone',
                                    icon: 'fa fa-trash',
                                    url: 'steward_withdraw/del',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.status == '3'){
                                            return true;
                                        }
                                        return false;
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        example: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
